#include <gtk/gtk.h>
#include "common.h"

static gint count = 0;
static char buf[5];

void increase(GtkWidget *widget, gpointer label)
{
	++count;
	sprintf(buf, "%d", count);
	gtk_label_set_text(label, buf);
}

void decrease(GtkWidget *widget, gpointer label)
{
	--count;
	sprintf(buf, "%d", count);
	gtk_label_set_text(label, buf);
}

int main(int argc,char *argv[])
{
	GtkWidget    *window;
	GtkWidget    *button_plus;
	GtkWidget    *button_minus;
	GtkWidget    *frame;
	GtkWidget    *label;
	GdkColor     color_black_ = {0x0, 0x0, 0xFFFF, 0xFFFF};

	gtk_init(&argc,&argv);

	/* create the main, top level, window */
	window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
	gtk_window_set_title(GTK_WINDOW(window), TITLE);
	gtk_window_set_position(GTK_WINDOW(window), GTK_WIN_POS_CENTER);
	gtk_window_set_default_size(GTK_WINDOW(window), 250, 180);
	gtk_widget_modify_bg(window, GTK_STATE_NORMAL, &color_black_); /*设置为黑色背景*/

	frame = gtk_fixed_new();
	gtk_container_add(GTK_CONTAINER(window), frame);

	button_plus = gtk_button_new_with_label("+");
	gtk_widget_set_size_request(button_plus, 80, 35);
	gtk_fixed_put(GTK_FIXED(frame), button_plus, 50, 20);

	button_minus = gtk_button_new_with_label("-");
	gtk_widget_set_size_request(button_minus, 80, 35);
	gtk_fixed_put(GTK_FIXED(frame), button_minus, 50, 80);

	label = gtk_label_new("0");
	gtk_fixed_put(GTK_FIXED(frame), label, 190, 58);

	g_signal_connect(window,"destroy",G_CALLBACK(gtk_main_quit),NULL);
	g_signal_connect(button_minus, "clicked", G_CALLBACK(decrease), label);
	g_signal_connect(button_plus, "clicked", G_CALLBACK(increase), label);

    {
        GtkRequisition  req;
        gtk_widget_size_request(button_plus, &req);
        g_message("WH(%d, %d)", req.width, req.height);
    }

	/* make sure that everything, window and label, are visible */
	gtk_widget_show_all(window);

	/* start the main loop, and let it rest until the application is closed */
	gtk_main();

	return 0;
} 
